import Axios from 'axios'

const NET_ERROR = 'Network Error'

const request = Axios.create({
  baseURL: process.env.NODE_ENV === 'development' ? 'http://localhost:8868' : 'http://121.5.145.14:8868',
  // baseURL: 'http://121.5.145.14:8868',
  // timeout: 2500
})

request.interceptors.request.use(config => {
  return config
}, err => {
  return Promise.reject(err)
})

request.interceptors.response.use(response => {
  return response
}, err => {
  if (err.message === NET_ERROR) {
    return Promise.reject({
      message: '网络错误'
    })
  }
  return Promise.reject(err)
})

export default request
